<?php
defined('_JEXEC') or die('Restricted access');
$weblinkparams = $weblinkitems['params'];
unset($weblinkitems['params']);

if(!empty($weblinkparams['title'])):?><h3 class="weblinkinfo_title<?php echo $weblinkparams['suffix']; ?>"><?php echo $weblinkparams['title']; ?></h3><?php endif;
$count = 0;
$column = $params->get('column');
$width = floor( 100 / $column );
$blank = $column - (count($weblinkitems) - (floor(count($weblinkitems) / $column) * $column));
if($column > count($weblinkitems)){
	$column = count($weblinkitems);
	$width = floor( 100 / count($weblinkitems) );
	$blank = 0;
}

$empty = '';
if($blank > 0 && $column > $blank){
	for($i=0; $i < $blank; $i++){
		$empty .= '<td width="'. $width. '%">&nbsp;</td>';
	}
}
?>
<table class="weblinkinfo<?php echo $weblinkparams['suffix']; ?>" width="100%">
<?php
$i = 0;
foreach($weblinkitems as $links):
?>
<?php if(!$count):?>
<tr>
<?php endif;?>
	<td width="<?php echo $width;?>%" valign="top">
	<?php if(!empty($links['title']) && $weblinkparams['showcattitle']):?>
	<ul class="weblinkinfocat<?php echo $weblinkparams['suffix']; ?>">
		<li>
			<?php if(!empty($links['image']) && $weblinkparams['showthumb']):?>
			<?php echo JHTML::image(JRoute::_("images/stories/". $links['image']), $links['title'],'width='. $weblinkparams['catImageWidth']);?>
	      		<?php endif;?>
			<strong><?php echo $links['title']; ?></strong>
			<?php if(!empty($links['description']) && $weblinkparams['showCatDescription']):?>
	        				<br /> <?php echo $links['description']; ?>
	        		<?php endif;?>
	<?php endif;?>
	        	<ul>
	        <?php foreach($links['list'] as $link):
		        	$hits = '';
		        	if($weblinkparams['hit']):
		        		$hits = '<small>&nbsp;('. $link->hits. ')</small>';
		        	endif;?>
	        		<li>
	        		<a href="<?php echo $link->link; ?>" title="<?php echo $link->title; ?>" target="<?php echo $weblinkparams['target']; ?>">
	        		<?php echo $link->thumbnail. $link->title. $hits; ?>
	        		</a>
	        		<?php if($weblinkparams['showdesc'] && !empty($link->description)):?>
	        			<br /><small><?php echo $link->description;?></small>
	        		<?php endif;?>
	       	 	</li>
	        <?php endforeach;?>
		</ul>
	<?php if(!empty($links['title']) && $weblinkparams['showcattitle']):?>
		</li>
	</ul>
	<?php endif;?>
	</td>
<?php
	$count++;
	$i++;
	if($i >= (count($weblinkitems) - 1) && !empty($empty)){
		echo $empty;
	}
	if($count >= $column): $count = 0;
?>
</tr>
	<?php endif;?>
<?php endforeach; ?>
</table>
<?php
unset($weblinkparams);
unset($weblinkitems);